class RegistrationController < ApplicationController
  layout "login"
  
  def index
  end
  
  def register
    return if check_params(params[:user].nil?)

    @user = User.new(params[:user])
    @user.user_type = UserType.find(UserType::STUDENT[:id])
    passwd = PasswordGenerator.generate
    @user.password = passwd
    if @user.save
      Registration.deliver_confirmation(@user, passwd)    
      if (params[:request_teacher].to_i == 1)
        RequestTeacher.deliver_request(@user)
      end
      set_flash_info(FlashInfo.new("Registration succeed.<br/>Check Your email for password.", FlashInfo::NOTICE))
      redirect_to :controller => "login" and return
    else
      set_flash_info(FlashInfo.new("Registration failed.", FlashInfo::ERROR))
      render :action => :index
    end
  end
end